<template>
  <div class="collection-company">
    <menu-content-layout title="收藏企业">
      <template v-slot:icon>
        <img src="~/assets/images/collection-products1.png" alt="" />
      </template>

      <template v-slot:content>
        <div class="list">
          <div class="item cursor" v-for="(item, index) in list" :key="index" @click="handleDetail(item.merchant.mer_id)">
            <img :src="item.merchant && item.merchant.mer_avatar" alt="" class="pic" />

            <div class="name">
              {{ item.merchant && item.merchant.mer_name || '未填写名称' }}
            </div>

            <div class="icons-first">
              <div class="verified">
                <img src="~/assets/images/verified.png" alt="" />
                <span>已认证</span>
              </div>
              <div class="settle">
                <img src="~/assets/images/settle.png" alt="" />
                <span>入驻5年</span>
              </div>
            </div>

            <div class="icons-second">
              <div class="service-enterprise">
                <img src="~/assets/images/service-enterprise.png" alt="" />
                <span>服务企业</span>
              </div>
              <div class="btns">
                <span class="collect">
                  <button @click="quitCollect(item.type_id)" style="cursor: pointer">
                    <img src="~/assets/images/collectA.png" width="21px" height="19px" alt="" />
                    <span>已收藏</span>
                  </button>
                </span>
              </div>
            </div>
            <!-- 遮罩 -->
            <div
              class="mask"
              :style="{ visibility: item.invalid && 'visible' }"
              @click.stop
            >
              <div class="prompt">该企业已失效，请移除</div>
              <m-button @click="remove(item)">移除</m-button>
            </div>
          </div>
          <nodata message="暂无收藏企业" :status="listStatus"></nodata>
        </div>

        <m-pagination
          :pagination="total"
          :page-size="limit"
          @changePage="changeThisPage"
        />
      </template>
    </menu-content-layout>
  </div>
</template>

<script>
import MenuContentLayout from "@/components/common/menu-content-layout/MenuContentLayout"
import MPagination from "@/components/common/m-pagination/MPagination"
import MButton from "@/components/common/m-button/MButton"
import { getCollectStore, getCollection } from "@/request/api"

export default {
  name: "CollectionCompany",
  components: { MButton, MPagination, MenuContentLayout },
  data() {
    return {
      list: [],
      page: 1,
      listStatus: 1,
      total: 1,
      limit: 5,
      noPic: require("assets/images/nopic.jpg")
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listStatus = 1
      this.list = []
      let data = {
        page: this.page,
        limit: this.limit
      }
      getCollectStore(data).then((res) => {
        this.list = res.data.list
        this.total = res.data.count
        if (this.total === 0) {
          this.listStatus = 0
        } else {
          this.listStatus = 2
        }
        window.scrollTo({ top: 0 })
      }).catch(err => {
        this.$message.error(err.message)
      })
    },
    async quitCollect(id) {
      let params = { 
        type_id: id,
        type: 10
      }
      let res = await getCollection(params)
      if(res.status === 200) {
        this.$toastVant.success(res.message)
        this.getList()
      }else {
        this.$toastVant.fail(res.message)
      }
    },
    changeThisPage(page) {
      this.page = page
      this.getList()
    },
    toCateDetails(id, name) {
      this.$router.push({
        path: "/category/classify/" + id + "?name=" + name
      })
    },
    handleDetail(id) {
      this.$router.push('/company-home/home/'+id)
    },
    remove(item) {
      console.log(item+'item');
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/style/common.scss";

.collection-company {
  /deep/ .collect .m-button .el-button,
  /deep/ .share .el-button {
    height: 30px;
    line-height: 30px;
    padding: 0 15px;
  }
  /deep/ .m-pagination {
    padding: 20px;
  }
  /deep/ .content {
    padding: 18px 5px;
  }
  .list {
    color: #666 !important;
    background: #fff;
    .item {
      width: 31.65%;
      background-color: #f5f4f9;
      display: inline-flex;
      flex-direction: column;
      position: relative;
      margin: 0 7px;
      margin-bottom: 14px;

      .pic {
        height: 150px;
        background-color: #ccc;
        margin: 10px;
        margin-bottom: 15px;
        object-fit: cover;
      }

      .name {
        // height: 42px;
        @include text-omitted(2);
        padding: 0 10px;
        margin-bottom: 20px;
      }

      .icons-first {
        display: flex;
        align-items: center;
        padding: 0 10px;
        margin-bottom: 15px;
        font-size: 14px;

        .verified {
          display: flex;
          color: $theme-color-1;
          width: 50%;

          img {
            margin-right: 5px;
          }
        }

        .settle {
          display: flex;
          width: 50%;

          img {
            margin-right: 5px;
          }
        }
      }

      .icons-second {
        display: flex;
        align-items: center;
        padding: 0 10px;
        margin-bottom: 30px;

        .service-enterprise {
          display: flex;
          width: 48%;
          font-size: 14px;

          img {
            margin-right: 5px;
          }
        }

        .btns {
          display: flex;

          .share {
            margin-right: 5px;

            button {
              background-color: #ffffff;
              width: 70px;
              display: flex;
              align-items: center;
              height: 24px;
              font-size: 12px;
              border-radius: 5px;

              span {
                margin-left: 5px;
                line-height: 22px;
              }
            }
          }

          .collect {
            button {
              display: flex;
              align-items: center;
              height: 24px;
              background-color: #F5F4F9;
              font-size: 14px;
              text-align: center;
              border-radius: 5px;

              span {
                // color: #fff;
                // line-height: 22px;
                margin-left: 5px;
              }
            }
          }
        }
      }

      .mask {
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        position: absolute;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background-color: rgba(102, 102, 102, 0.5);
        visibility: hidden;

        .prompt {
          color: #fff;
          font-size: 14px;
          margin-bottom: 15px;
        }
      }
    }
  }
}
</style>
